package com.lee.transactionaldemo.service.supprots;

import com.lee.transactionaldemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：liylw
 * @date ：Created in 2021/4/23 10:57
 */
@Service
public class Supprots1 {
    @Autowired
    private Supprots2 supprots2;

    @Autowired
    private UserService userService;


    /**
     * 都插入，没有回滚
     */
    public void test1(){
        supprots2.testSuccess();
        userService.saveUserAFail();
    }


    /**
     * 都没插入，回滚
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void test2(){
        supprots2.testSuccess();
        userService.saveUserAFail();
    }


    /**
     * 都没插入，回滚
     */
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void test3(){
        userService.saveUserASuccess();
        supprots2.testFail();
    }
}
